home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / dbf_tc.zip / D_GETREC.C < prev    next >
Text File  |  1987-06-06  |  1KB  |  36 lines

  1. /* 
  2. **        file:        d_getrec.c
  3. **        purpose:    routine to get a record from a dbiii file and place in memory at
  4. **                    location pointed to by DBF.record_prt.
  5. **        ussage:    d = (struct DBF *)malloc(sizeof(struct DBF));
  6. **                    strcpy(d->filename,"filename.dbf");
  7. **                    d_open(d);
  8. **                    d_getrec(d,(long)record);
  9. **                    ... access record as desired ...
  10. **                    d_close(d);
  11. **                    free(d);
  12. **        notes:    compile with "tcc -c d_getrec".    include this file in dbf.lib
  13. **                    see dbf.h for structure of DBF
  14. **        returns:    0                    if successfull
  15. **                    RECNO_TOO_BIG    if record is not in database
  16. **        author:    Mark Sadler
  17. **        revised:    6/6/87
  18. */ 
  19. #include <stdio.h>
  20. #include "dbf.h"
  21.  
  22. int d_getrec(struct DBF *d,unsigned long int r)
  23. {
  24.     if(r > d->records)
  25.         return(RECNO_TOO_BIG);
  26.     if (r > 0L)
  27.         {
  28.         fseek(d->file_ptr,((long)d->header_length + ((r - 1L) * d->record_length)),0);
  29.         fread(d->record_ptr,d->record_length,1,d->file_ptr);
  30.         d->current_record = r;
  31.         return(0);
  32.         }
  33.     return(RECNO_TOO_BIG);
  34. }
  35.  
  36.